package com.mapforge.gui.frames.tileset;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

import com.mapforge.Constants;
import com.mapforge.collection.WeakReferenceInstanceProvider;
import com.mapforge.listener.TilesetEditListener;
import com.mapforge.map.Tileset;

/**
 * Tracks the state of the tileset properties dialog. Just its parent frame and
 * any registered tileset listeners for now.
 * 
 * @author William Morrison
 * 
 */
public class NewTilesetDialogProvider extends
		WeakReferenceInstanceProvider<NewTilesetDialog> implements
		ActionListener {
	private JFrame frame;
	private List<TilesetEditListener> tilesetEditListeners;

	public NewTilesetDialogProvider(JFrame frame) {
		this.frame = frame;
		tilesetEditListeners = new ArrayList<TilesetEditListener>();
	}

	public void addTilesetEditListener(TilesetEditListener listener) {
		tilesetEditListeners.add(listener);
	}

	public void clearTilesetEditListeners() {
		tilesetEditListeners.clear();
	}

	protected NewTilesetDialog createNewInstance() {
		NewTilesetDialog dialog = new NewTilesetDialog(frame, new Tileset(
				"Untitled", Constants.DEFAULT_TILE_DIMENSION.width,
				Constants.DEFAULT_TILE_DIMENSION.height), tilesetEditListeners);
		return dialog;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		//TODO finish NewTilesetDialog
		// this.getInstance().setVisible(true);
	}

}
